<#assign packageModel=projPackage.entity valuePrefix="#{"
        utilsPackage=projPackage.projPackage + "." + projPackage.utils
        controllerPackage=projPackage.projPackage + "." + projPackage.controller
        serviceImplPackage=projPackage.projPackage + "." + projPackage.service
        serviceFullPackage="account.service." + tableInfo.modelClassName + "Service"
        daoFullPackage=projPackage.projPackage + "." + projPackage.dao + "." +tableInfo.modelClassName+"Mapper"
        modelFullPackage="account.entity." +tableInfo.modelClassName>
package account.controller.forms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import ${modelFullPackage};
import ${serviceFullPackage};
import account.entity.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import account.entity.ResponseResult;
import account.util.ResultCode;

/**
 * 注意要有依赖：
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger2</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 *         <dependency>
 *             <groupId>io.springfox</groupId>
 *             <artifactId>springfox-swagger-ui</artifactId>
 *             <version>2.9.2</version>
 *         </dependency>
 * 同时入口类头上使用注解：@EnableSwagger2
 * @Description : 控制层，自定义代码写在最后
 * @Author : chanchaw
 * @Date : ${.now?date} ${.now?time}
 */
@CrossOrigin
@RestController
@RequestMapping("/${tableInfo.modelClassName?uncap_first}")
public class ${tableInfo.modelClassName}Controller {
    @Autowired
    private ${tableInfo.modelClassName}Service service;

    // 全部属性新增
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResult<${tableInfo.modelClassName}> insert(@RequestBody ${tableInfo.modelClassName} record){
        return new ResponseResult<${tableInfo.modelClassName}>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.insert(record));
    }

    // 选择属性新增。value=null 的属性不会写入DB，DB会填充默认值
    @RequestMapping(value = "/insertSelective", method = RequestMethod.POST)
    public ResponseResult<${tableInfo.modelClassName}> insertSelective(@RequestBody ${tableInfo.modelClassName} record){
        return new ResponseResult<${tableInfo.modelClassName}>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.insertSelective(record));
    }

    <#list tableInfo.fieldInfoList as field>
    <#if field.primaryKey=true>
    // 根据主键删除，切记表要有主键，否则为删除所有数据！！！！！！！！！！
    @RequestMapping(value = "/delete/{pk}", method = RequestMethod.POST)
    public ResponseResult<Integer> deleteByPrimaryKey(@PathVariable ${field.javaType} pk){
        return new ResponseResult<Integer>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.deleteByPrimaryKey(pk));
    }

    // 根据主键查询，切记表要有主键，否则为查询所有数据！！！！！！！！！！
    @RequestMapping(value = "/select/{pk}", method = RequestMethod.POST)
    public ResponseResult<${tableInfo.modelClassName}> selectByPrimaryKey(@PathVariable ${field.javaType} pk){
        return new ResponseResult<${tableInfo.modelClassName}>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.selectByPrimaryKey(pk));
    }
    </#if>
    </#list>

    // 获取所有数据
    @RequestMapping(value = "/selectAll", method = RequestMethod.POST)
    public ResponseResult<List<${tableInfo.modelClassName}>> selectAll(){
        return new ResponseResult<List<${tableInfo.modelClassName}>>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.selectAll());
    }

    // 全部属性更新。前端传递来属性value=null则会设置后台数据为null
    @RequestMapping(value = "/updateByPrimaryKey", method = RequestMethod.POST)
    public ResponseResult<Integer> updateByPrimaryKey(@RequestBody ${tableInfo.modelClassName} record) {
        return new ResponseResult<Integer>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.updateByPrimaryKey(record));
    }

    // 部分属性更新。前端传递来value=null的属性不会被更新到数据库
    @RequestMapping(value = "/updateByPrimaryKeySelective", method = RequestMethod.POST)
    public ResponseResult<Integer> updateByPrimaryKeySelective(@RequestBody ${tableInfo.modelClassName} record) {
        return new ResponseResult<Integer>(ResultCode.OK.getCode(), ResultCode.OK.getMsg(), service.updateByPrimaryKeySelective(record));
    }
    //=================以上是自动生成的代码，自定义代码请写在下面==================
}